package com.catering.config;

import com.alibaba.fastjson.JSON;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;

public class Sample {
    public static void show(String signName, String templateCode,String phoneNumbers,String param) throws Exception {
        Client client = Sample.createClient();
        if (client == null) {
            System.err.println("Client is null, please check the configuration.");
            return;
        }
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(phoneNumbers)
                .setSignName(signName)
                .setTemplateCode(templateCode)
                .setTemplateParam("{\"code\":\""+param+"\"}");
        // 打印请求对象，确保所有字段都已正确设置
        System.out.println(JSON.toJSONString(sendSmsRequest));
        try {
            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
            // 打印响应对象
            System.out.println(JSON.toJSONString(sendSmsResponse));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Client createClient() throws Exception {
        // 这里假设你已经实现了 createClient 方法
        // 确保返回一个有效的 Client 实例
        return new Client(new Config()
                .setAccessKeyId("LTAI5tBjWuNVNNASuheEsSjc")
                .setAccessKeySecret("LhJ9celmL1natht454xEC1YBgDRtMG"));
    }
}
